package com.txm.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.txm.dao.BaseDao;
import com.txm.dao.CityRepository;
import com.txm.mapper.TestMapper;
import com.txm.model.Blog.Article;
import com.txm.model.hibernate.Hibernate;
import com.txm.model.hibernate.User;
import com.txm.model.mvc.Chapter;
import com.txm.model.mvc.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/1.
 */
@Service
public class TestService {
    @Autowired
    private BaseDao baseDao;
    @Autowired(required = true)
    private TestMapper testMapper;
    /*    @Autowired*/
    private CityRepository cityRepository;

    public void test() {
        System.out.println("1243545");
    }

    public Course getCoursebyId(Integer courseId) {

        Course course = new Course();

        course.setCourseId(courseId);
        course.setTitle("深入浅出Java多线程");
        course.setImgPath("resources/imgs/course-img.jpg");
        course.setLearningNum(12345);
        course.setLevel(2);
        course.setLevelDesc("中级");
        course.setDuration(7200l);
        course.setDescr("多线程是日常开发中的常用知识，也是难用知识。bala bala...");
        List<Chapter> chapterList = new ArrayList<Chapter>();
        course.setChapterList(chapterList);
        return course;

    }


    @Transactional
    public void save(Hibernate hibernate) {
        baseDao.merge(hibernate);
    }

    @Transactional
    public List<User> list() {
        Page page = new Page();
        page.setPageNum(1);
        page.setPageSize(3);
        page = baseDao.page("from User", page);
        return baseDao.list("from User");
    }

    public void selectJpa() {
        Page<Article> user = testMapper.findArticle();
        String countColumn = user.getCountColumn();
       List<Article> articles= user.getResult();
        Page<Article> page = PageHelper.getLocalPage();
        System.out.printf("");

        /*Iterable<City> dd = cityRepository.findAll();
        System.out.printf("");*/

    }
}